<?php

class Core_Listener
{
    static public function onRequestStartup()
    {

    }

    static public function onRequestShutdown()
    {
        if (STATS_REQUEST == 'Off')
        {
            return;
        }

        $request = Nuo::getRequest();

        $data = array();

        $table = Nuo::getResource('core@stats.request', 'table');

        $table -> insert(array(
            'owner' => isset($_SESSION['UID']) ? $_SESSION['UID']: '',
            'http_method' => $request -> getMethod(),
            'request_uri' => $_SERVER['REQUEST_URI'],
            'remote_addr' => $request -> getClientIp(),
            'action_id' => $request -> getActionId(),
            'request_params' => var_export($request -> getParams(), 1),
            'mem_usage' => (memory_get_usage() - NUO_START_MEM) / pow(2, 20),
            'time_usage' => microtime(1) - NUO_START_TIME,
            'request_date' => date('Y-m-d H:i:s'),
        ));
    }

    /**
     * process render page start
     * process hook or some thing else
     */
    static public function onRenderPageStartup()
    {
        // to do here
    }

    /**
     * process render page start
     * process hook or some thing else
     */
    static public function onRenderPageShutdown()
    {

    }

}
